<%@ page contentType="text/html;charset=UTF-8" %>
	<%@ include file="/common/taglibs.jsp" %>
		<!DOCTYPE html>
		<html lang="en">

		<head>
			<%@ include file="/common/common-css.jsp" %>
				<style>
					#jquery-table td {
						cursor: pointer !important
					}
					
					.load_bg {
						background: #000;
						opacity: 0.1;
						left: 0px;
						top: 0px;
						position: fixed;
						height: 100%;
						width: 100%;
						overflow: hidden;
						z-index: 10000;
					}
					
					.load_img {
						left: 50%;
						top: 180px;
						position: fixed;
						height: 50px;
						overflow: hidden;
						z-index: 20000;
					}
					
					label {
						width: 100%;
						margin-bottom: 10px;
						position: relative;
						font-size: 13px;
					}
					
					.btn-add {
						position: absolute;
						top: 50%;
						transform: translateY(-50%);
						-webkit-transform: translateY(-50%);
						right: 0;
					}
					
					.btn-add:active {
						top: 50% !important;
					}
					
					.input-group {
						margin-bottom: 10px;
					}
					
					.list-group-2 .form-control:nth-last-child(2) {
						width: 48.5%;
						margin-right: 3%;
					}
					
					.list-group-2 .form-control:nth-last-child(1) {
						width: 48.5%;
					}

					.list-group-3 .form-control:nth-last-child(2),
					.list-group-3 .form-control:nth-last-child(3) {
						width: 31%;
						margin-right: 3%;
					}
					.list-group-3 .form-control:nth-last-child(1){
						width: 31%;
					}
					
					input[type=checkbox],
					input[type=radio] {
						position: relative;
						top: 2px;
						left: 10px;
					}

					input[type=text]{
						font-size: 13px;
					}
					
					.glyphicon-picture {
						top: 0;
						left: 0;
						font-size: 16px;
						cursor: pointer;
					}
					
					.textarea {
						min-height: 150px;
						max-height: 350px;
						height: auto;
						overflow-y: scroll;
    					overflow-x: hidden;
						font-size: 13px;
					}

					.textarea::-webkit-scrollbar {
						width: 0;
					}

					.textarea img{
						max-width: 50%;
					}
					
					.list-group.has-glyphicon {
						padding-left: 105px !important;
					}
					
					.list-group .glyphicon-group {
						position: absolute;
						top: 0;
						z-index: 2;
						width: 34px;
						height: 34px;
						line-height: 34px;
						text-align: center;
						display: block;
						cursor: pointer;
					}
					
					.list-group .glyphicon-group:hover {
						background-color: #e2e2e2;
					}
					
					.list-group .glyphicon-group:nth-child(1) {
						color: #a94442;
						left: 0;
					}
					
					.list-group .glyphicon-group:nth-child(2) {
						color: #428bca;
						left: 34px;
					}
					
					.list-group .glyphicon-group:nth-child(3) {
						color: #428bca;
						left: 68px;
					}
					
					.view-image {
						width: 80%;
						height: 100%;
						position: absolute;
						top: 0;
						right: 0;
					}

					.view-image img{
						height: 80px;
					}
					
					.form-group {
						position: relative;
					}
					
					button.get-img-modal {
						margin-bottom: 10px;
					}
				</style>
		</head>

		<body class="no-skin">
			<div class="load_bg" style="display:none"></div>
			<img src="http://img.xmiles.cn/commentloading.gif" class="load_img" style="display:none" />
			<div class="page-content">
				<div class="page-content-area">
					<div class="widget-box widget-color-blue">
						<div class="widget-body">
							<div class="widget-main">
								<form id="submitForm" action="">

								</form>
							</div>
							<!-- /.widget-main -->
						</div>
						<!-- /.widget-body -->
					</div>
					
					<div class="row text-center" style="margin-top:27px;">
						<button class="btn btn-lg btn-default no-border" id="cancel" style="margin-right:20px;">
							<i class="ace-icon fa fa-reply"></i> 取消
						</button>
						<button class="btn btn-lg btn-primary no-border" id="refresh" style="margin-right:20px;">
							<i class="ace-icon fa fa-refresh"></i> 刷新
						</button>
						<button class="btn btn-lg btn-success no-border" id="save">
							<i class="ace-icon fa fa-floppy-o"></i> 确认
						</button>
					</div>

					<!-- /.widget-box -->
				</div>
				<!-- /.page-content-area -->
			</div>
			<!-- /.page-content -->

			<!--模态框-->
			<div class="modal fade" id="Modal">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title">上传图片</h4>
						</div>
						<div class="modal-body clearfix">
							<form id="addImage" method="post" enctype="multipart/form-data">
								<div class="row">
									<div class="form-group col-xs-12">
										<div class="input-group col-sm-12">
											<input type="file" class="form-control" name="myFile" />
										</div>
									</div>
								</div>
							</form>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
							<button type="button" class="btn btn-primary" disabled id="confirm">上传</button>
						</div>
					</div>
					<!-- /.modal-content -->
				</div>
				<!-- /.modal-dialog -->
			</div>
			<!-- /.modal -->
		    <link rel="stylesheet" href="${ctx}/ace/css/just-tip.css" />

	<%@ include file="/common/common-js.jsp" %>

	<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
	<script src="${ctx}/ace/js/justTools.js"></script>
	<script type="text/javascript" src="${ctx}/js/jquery.form.js"></script>
	<script type="text/javascript">
	
	//获取链接参数的方法
	function getQueryString(name){
		var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if(r!=null)return unescape(r[2]); return null;
    };

	var aid = getQueryString('avtivityId'),
		mid = getQueryString('modelId');

	//数据分隔符
	var itemSplit = '0x80072EE2',
		childItemSplit = '0x80072EE7';

	//排序标签
	var glyphiconHtml = '<span class="glyphicon glyphicon-remove glyphicon-group"></span>'
				+ '<span class="glyphicon glyphicon-chevron-up glyphicon-group"></span>'
				+ '<span class="glyphicon glyphicon-chevron-down glyphicon-group"></span>';
	
	//提示的方法
	function backupTextJustToolsTip(dom, content, theme){
		dom.justToolsTip({
			animation: 'moveInLeft',
			contents: content,
			theme: theme,
			gravity: 'left'
		});
		setTimeout(function(){
			$('.just-tooltip').remove();
		},3000); 
	};

	//定义上传图片前光标位置--jq对象
	var currentSelectionAnchorNode, selectionAnchorNodeFromText = false;

	//编辑区域插入图片的方法
	function insertImg(src) {
		if (currentSelectionAnchorNode) {
			//有选区，且选区数量是一个，且选区的起始点和终点在同一位置//getRangeAt/anchorNode
			var img = new Image();
			img.src = src;
			if(!selectionAnchorNodeFromText){
				currentSelectionAnchorNode.append(img);
			}else{
				currentSelectionAnchorNode.after(img);
			}
			//删除空格,避免将不必要的内容上传至服务器
			currentSelectionAnchorNode.parent('.textarea').find('div').each(function(){
				if($(this).html() == '<br>' || $(this).html().trim() == ''){
					$(this).remove();
				}
			});
		}
	};

	//上传到七牛的方法
	function uploadImage() {
		
		var options = {
			url : "${ctx}/module/fileupload/fileUpload.action",
			type : "POST",
			dataType : "json",
			beforeSend: function(){
				$(".load_bg,.load_img").show();
			},
			success : function(data) {
				var dataList = data.split('#')[0];
				if(window.insertType == 1){
					//对隐藏的input赋值
					$(window.$input).val(dataList);
					/* $("input[name='apply_process']").val(dataList); */
					$(window.$selector).html('<img src="' + dataList + '" />');
					/* $("input[name='apply_process']").next("div").html('<img src="' + dataList + '" />'); */
					
				}else if(window.insertType == 2){
					insertImg(dataList);	
				}

				//隐藏模态框
				$('#Modal').modal('hide');	
				//清空modal里面的input的值
				$('input[name="myFile"]').val('');
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				alert(textStatus);
			},
			complete: function(){
				$(".load_bg,.load_img").hide();
			}
		}; 
		$('#addImage').ajaxSubmit(options); 
	};

	//表单异步提交
	function saveForm(){
		var options = { 
			url : '${ctx}/advertActivity/activityVarsUpdate.action',
			type : "POST",
			data : {"aid": aid},
			dataType : "json",
			beforeSend: function(){
				$(".load_bg,.load_img").show();
			},
			success : function(data) {
				console.log('表单提交成功:', data);
				window.location.href = '${ctx}/module/activityList.jsp';
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				alert(textStatus);
				console.log(XMLHttpRequest, textStatus, errorThrown);
			},
			complete : function(){
				$(".load_bg,.load_img").hide();
			}
		};
		$('#submitForm').ajaxSubmit(options);
	};

	//查询表单数据的方法
	function queryForm(callback){
		var options = { 
			url : '${ctx}/apiactivity/selectActivity.action',
			type : "POST",
			data : {"modelId": mid, "activityId": aid},
			dataType : "json",
			beforeSend: function(){
				$(".load_bg,.load_img").show();
			},
			success : function(data) {
				console.log('初始化数据查询成功');
				// var _data = [
				// 		{
				// 			content:"name0",
				// 			name:"理财方名称",
				// 			remark:"测试remark",
				// 			sort:0,
				// 			type:1,
				// 			val:"测试理财方"
				// 		}
				// 	];
				callback(data);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				alert(textStatus);
				console.log(XMLHttpRequest, textStatus, errorThrown);
			},
			complete : function(){
				$(".load_bg,.load_img").hide();
			}
		};
		$.ajax(options);
	};

	var textareaDefaultDOM = '<div style="height:1px;display:none;">&nbsp;</div>';

	//查询表单数据成功后回调的方法--data为list
	var queryFormCallBack = function(data){

		if(data && data.length > 0){

			var rowHeader = '<div class="row">',
				rowFooter = '</div>';
			
			var allHtml = '';
			
			//非图文类型每两个一组
			for(var i = 0; i < data.length; i ++){

				var item = data[i];

				//var itemHtml = '';

				//初始化循环到复数的时候重置itemHtml为rowHeader
				//if(i % 2 === 0){
				var itemHtml = rowHeader;
				//}

				var titleText = item.remark ? item.title + '(' + item.remark + ')' : item.name,
					titleTips = '';//' -- PS:不允许出现连续字符0x80072EE2或者0x80072EE7';

				//为保证id的唯一性,使用content+type+i混合的方式生成
				var uniqueness = item.keyName + item.modelType + i;

				var sVal = '';
				if(item.val){
					sVal = item.val;
				}
				
				//type--选项类型,0:输入框,1:图片，2：图文，3：时间，4：单选框，5：列表1,6：列表2,7:列表3
				switch(item.modelType){
					case "0":
						itemHtml += '<div class="form-group col-sm-12 col-xs-12">'
								+		'<label class="control-label" for="' + uniqueness + '">' + titleText + ':</label>'
								+		'<div class="input-group col-sm-12 col-xs-12" model-type="input">'
								+			'<input class="form-control has-data-val" data-value="' + encodeURI(sVal) + '" type="text" name="' 
								+                 item.keyName + '" id="' + uniqueness + '" key-name="'+item.keyName+'"/>'
								+		'</div>'
								+	'</div>';
						break;
					case "1":
						var img = '';
						if(item.val){
							img = '<img src="' + item.val + '" />';
						}
						itemHtml += '<div class="form-group col-sm-12 col-xs-12">'
								+		'<label class="control-label" for="' + uniqueness + '">' + titleText + ':</label>'
								+		'<button class="btn btn-sm btn-primary get-img-modal" data-insert-type="1" data-selector=".' + uniqueness + '" data-input=".' 
								+            uniqueness + '" id="' + uniqueness + '">选择</button>'
								+		'<input class="' + uniqueness + '" name="' + item.content + '" type="hidden" value=' + sVal + ' />'
								+		'<div class="view-image ' + uniqueness + '">' + img + '</div>'
								+	'</div>';
						break;
					case "2":
						var content = textareaDefaultDOM + '<div>请填写内容...</div>';
						if(item.val){
							content = item.val;
						}
						itemHtml += '<div class="form-group col-sm-12 col-xs-12">'
								+		'<label class="control-label" for="' + uniqueness + '">' + titleText + ' -- PS:请删除默认文案后填写' + '</label>'
								+		'<div class="input-group col-sm-12 col-xs-12 relative">'
								+			'<span class="glyphicon glyphicon-picture get-img-modal" data-insert-type="2"></span>'
								+			'<div class="form-control textarea" contentEditable="true" id="' + uniqueness + '">'
								+				content
								+			'</div>'
								+           '<input class="textarea-input" type="hidden" name="' + item.keyName + '" id="' + uniqueness + '" />'
								+		'</div>'
								+	'</div>';
						break;
					case "3":
						itemHtml += '<div class="form-group col-sm-12 col-xs-12">'
								+		'<label class="control-label" for="' + uniqueness + '">' + titleText + '</label>'
								+		'<div class="input-group col-sm-12 col-xs-12" model-type="datetime">'
								+			'<input class="form-control date-picker" type="text" name="' + item.keyName + '" id="' + uniqueness 
								+ 				'" value="' + sVal + '" key-name="'+item.keyName+'"/>'
								+		'</div>'
								+	'</div>';
						break;
					case "4":
						var selected0 = '', selected1 = '';
						if(item.val == 1){
							selected1 = 'selected';
						}else{
							selected0 = 'selected';
						}
						itemHtml += '<div class="form-group col-sm-12 col-xs-12">'
								+		'<label class="control-label" for="' + uniqueness + '">' + titleText + '</label>'
								+		'<div class="input-group col-sm-12 col-xs-12">'
								+			'<select class="form-control" name="' + item.keyName + '" id="' + uniqueness + '">'
								+				'<option value="0" ' + selected0 + '>否</option>'
								+				'<option value="1" ' + selected1 + '>是</option>'
								+			'</select>'
								+		'</div>'
								+	'</div>';
						break;
					case "5":
						var val, inputHtml = '';
						if(item.val){
							val = item.val.split(itemSplit);
							var sign = '', glyClass = '';
							if(val.length > 1){
								sign = glyphiconHtml;
								glyClass = 'has-glyphicon';
							}
							inputHtml += '<div model-type="list1">';
							for(var j = 0; j < val.length; j ++){
								inputHtml += '<div class="input-group list-group ' + glyClass + ' col-sm-12 col-xs-12" key-name="'+item.keyName+j+'">'
									+            sign
									+			 '<input class="form-control has-data-val" data-value="' + encodeURI(val[j]) 
									+ 				'" type="text" key-name="'+item.keyName+'"/>'
									+		 '</div>';
							}
						}else{
							inputHtml += '<div class="input-group list-group col-sm-12 col-xs-12"  key-name="'+item.keyName+1+'">'
								+			 '<input class="form-control" type="text" />'
								+		 '</div>';
						}
						inputHtml += '</div>';
						itemHtml += '<div class="form-group form-group-with-list col-sm-12 col-xs-12">'
								+		'<label class="control-label" for="' + uniqueness + '">'
								+			titleText + titleTips + ':'
								+			'<button class="btn btn-xs btn-primary btn-add list-add">'
								+				'<span class="glyphicon glyphicon-plus"></span>'
								+			'</button>'
								+			'<input type="hidden" name="' + item.keyName + '" id="' + uniqueness + '" />'
								+		'</label>' 
								+		inputHtml
								+	'</div>';
						break;
					case "6":
						var val, inputHtml = '';
						if(item.val){
							val = item.val.split(itemSplit);
							var sign = '', glyClass = '';
							if(val.length > 1){
								sign = glyphiconHtml;
								glyClass = 'has-glyphicon';
							}
							inputHtml += '<div model-type="list2">';
							for(var j = 0; j < val.length; j ++){
								var _val = val[j].split(childItemSplit);
								inputHtml += '<div class="input-group list-group list-group-2 ' + glyClass + ' col-sm-12 col-xs-12" key-name="'+item.keyName+j+'">'
									+            sign
									+			 '<input class="form-control has-data-val" data-value="' + encodeURI(_val[0]) + '" type="text" />'
									+			 '<input class="form-control has-data-val" data-value="' + encodeURI(_val[1]) + '" type="text" />'
									+		 '</div>';
							}
						}else{
							inputHtml += '<div class="input-group list-group list-group-2 col-sm-12 col-xs-12" key-name="'+item.keyName+1+'">'
								+			 '<input class="form-control" type="text" />'
								+			 '<input class="form-control" type="text" />'
								+		 '</div>';
						}
						inputHtml += '</div>';
						itemHtml += '<div class="form-group form-group-with-list form-group-with-list-2 col-sm-12 col-xs-12">'
								+		'<label class="control-label" for="' + uniqueness + '">'
								+			titleText + titleTips + ':'
								+			'<button class="btn btn-xs btn-primary btn-add list-add">'
								+				'<span class="glyphicon glyphicon-plus"></span>'
								+			'</button>'
								+			'<input type="hidden" name="' + item.keyName + '" id="' + uniqueness + '" />'
								+		'</label>'
								+		inputHtml
								+	'</div>';
						break;
					case "7":
						var val, inputHtml = '';
						if(item.val){
							val = item.val.split(itemSplit);
							var sign = '', glyClass = '';
							if(val.length > 1){
								sign = glyphiconHtml;
								glyClass = 'has-glyphicon';
							}
							inputHtml += '<div model-type="list3">';
							for(var j = 0; j < val.length; j ++){
								var _val = val[j].split(childItemSplit);
								inputHtml += '<div class="input-group list-group list-group-3 ' + glyClass + ' col-sm-12 col-xs-12" key-name="'+item.keyname+j+'">'
									+            sign
									+			 '<input class="form-control has-data-val" data-value="' + encodeURI(_val[0]) + '" type="text" />'
									+			 '<input class="form-control has-data-val" data-value="' + encodeURI(_val[1]) + '" type="text" />'
									+			 '<input class="form-control has-data-val" data-value="' + encodeURI(_val[2]) + '" type="text" />'
									+		 '</div>';
							}
						}else{
							inputHtml += '<div class="input-group list-group list-group-3 col-sm-12 col-xs-12" key-name="'+item.keyname+1+'">'
								+			 '<input class="form-control" type="text" />'
								+			 '<input class="form-control" type="text" />'
								+			 '<input class="form-control" type="text" />'
								+		 '</div>';
						}
						inputHtml += '</div>';
						itemHtml += '<div class="form-group form-group-with-list form-group-with-list-3 col-sm-12 col-xs-12">'
								+		'<label class="control-label" for="' + uniqueness + '">'
								+			titleText + titleTips + ':'
								+			'<button class="btn btn-xs btn-primary btn-add list-add">'
								+				'<span class="glyphicon glyphicon-plus"></span>'
								+			'</button>'
								+			'<input type="hidden" name="' + item.keyName + '" id="' + uniqueness + '" />'
								+		'</label>'
								+		inputHtml
								+	'</div>';
						break;
				}
				//循环到单数的时候itemHtml拼接rowFooter
				//if(i % 2 !== 0 || i + 1 === data.length){
				itemHtml += rowFooter;
				//}

				//为了方便计算,把itemHtml添加到allHtml上
				allHtml += itemHtml;
				/*
				$('#submitForm').append(itemHtml);
				if(item.type === 0){
					$('#submitForm').find('input').last().val(sVal);
				}
				*/
			}
			$('#submitForm').html(allHtml);

			$('.has-data-val').each(function(){
				var val = $(this).data('value');
				$(this).val(decodeURI(val));
			});

			//初始化时间控件
			$('.date-picker').datetimepicker({
				autoclose:true,
				startDate: new Date(),
				format: "yyyy-mm-dd hh:ii:ss"
			}).next().on(ace.click_event, function(){
				$(this).prev().focus();
			});
		}
	}

	//绑定
	$(function(){

		queryForm(queryFormCallBack);

		//监听鼠标,键盘离开事件--设置输入域光标
		$('body').on('click keydown', '.textarea', function(){
			var anchorNode = window.getSelection().anchorNode;
			//判断当前光标位置处于文字/DOM
			if($(anchorNode)[0].clientHeight != undefined){
				selectionAnchorNodeFromText = false;
				currentSelectionAnchorNode = $(anchorNode);
			}else{
				selectionAnchorNodeFromText = true;
				currentSelectionAnchorNode = $(anchorNode).parent();
			}
			if($(this).html().trim() == ''){
				$(this).prepend(textareaDefaultDOM);
			}
		});

		//上传图片事件
		$('body').on('click', '.get-img-modal', function(){
			var $this = $(this);
			window.insertType = $this.attr('data-insert-type');
			if(window.insertType == 1){
				window.$input = $this.attr('data-input');
				window.$selector = $this.attr('data-selector');
			}
			//计算位置并展示模态框
			//var top = $this.parent().position().top;
			//$('#Modal').css('top', top).modal('show');
			$('#Modal').modal('show');
			return false;
		});
		$('input[name="myFile"]').on('change', function(){
			if($(this).val() != ''){
				$('#confirm').prop('disabled', false);
			}else{
				$('#confirm').prop('disabled', true);
			};
		});
		$('#confirm').on('click', function(){
			if($('input[name="myFile"]').val() != ''){
				uploadImage();
			};
			return false;
		});

		//list操作
		$('body').on('click', '.list-add', function(e){
			var container = $(this).parent('label').parent('.form-group');
			var inputGroup = container.children('.input-group');
			var inputGroupLength = inputGroup.length;
			if(inputGroupLength > 0){
				inputGroup.addClass('has-glyphicon').find('.glyphicon-group').remove();
				inputGroup.prepend(glyphiconHtml);
			}
			//复制第一个
			var	firstElement = inputGroup.eq(0).clone();
			firstElement.find('input').val('');
			firstElement.appendTo(container);
			return false;
		});
		$('body').on('click', '.glyphicon-group', function(e){
			var container = $(this).parent('.input-group').parent('.form-group');
			var inputGroup = container.children('.input-group');
			var thisInputGroup = $(this).parent('.input-group');
			var inputGroupLength = inputGroup.length;
			if($(this).hasClass('glyphicon-remove')){
				//删除
				if(inputGroupLength === 2){
					inputGroup.removeClass('has-glyphicon').find('.glyphicon-group').remove();
					thisInputGroup.remove();
				}else if(inputGroupLength > 2){
					thisInputGroup.remove();
				}
			}else if($(this).hasClass('glyphicon-chevron-up')){
				//上移--上方有label,初始值为1
				var index = thisInputGroup.index();
				if(index === 1){
					alert('已经置顶了');
					return;
				}
				var thisHtml = thisInputGroup.clone();
				thisInputGroup.prev().before(thisHtml);
				thisInputGroup.remove();
			}else if($(this).hasClass('glyphicon-chevron-down')){
				//上移--上方有label,初始值为1
				var index = thisInputGroup.index();
				if(index === inputGroupLength){
					alert('已经置底了');
					return;
				}
				var thisHtml = thisInputGroup.clone();
				thisInputGroup.next().after(thisHtml);
				thisInputGroup.remove();
			}
			return false;
		});

		//取消按钮事件--回到列表
		$('#cancel').on('click', function(){
			window.location.href = '${ctx}/module/activityList.jsp';
		});

		//刷新按钮事件
		$('#refresh').on('click', function(){
			window.location.reload();
		});

		//保存按钮事件
		$('#save').on('click', function(){
			turnListGroupToVal();
			turnTextareaToVal();
			saveForm();
		});

		//图文类型的值转换保存
		function turnTextareaToVal(){
			$('.textarea').each(function(){
				var val = $(this).html();
				//删除顶部空格
				val = val.replace(new RegExp(textareaDefaultDOM, 'gm'), '');
				val = val.replace(new RegExp('<div>请填写内容...</div>', 'gm'), '');
				$(this).next('input[type=hidden]').val(val);
			});
		};

		//列表类型的值转换到可保存的值
		function turnListGroupToVal(){

			$('.form-group-with-list').each(function(){
				var $this = $(this);
				//3项列表
				if($this.hasClass('form-group-with-list-3')){
					var val = [];
					//循环子项
					$this.children('.list-group').each(function(){
						var $$this = $(this);
						var inputs = $$this.children('input'),
							input0 = inputs.eq(0).val(),
							input1 = inputs.eq(1).val(),
							input2 = inputs.eq(2).val();
						val.push(input0 + childItemSplit + input1 + childItemSplit + input2);
					});
					val = val.join(itemSplit);
					if(val == itemSplit || val == childItemSplit){
						$this.find('input[type=hidden]').val('');
					}else{
						$this.find('input[type=hidden]').val(val);
					}
				}
				//2项列表
				else if($this.hasClass('form-group-with-list-2')){
					var val = [];
					//循环子项
					$this.children('.list-group').each(function(){
						var $$this = $(this);
						var inputs = $$this.children('input'),
							input0 = inputs.eq(0).val(),
							input1 = inputs.eq(1).val();
						val.push(input0 + childItemSplit + input1);
					});
					val = val.join(itemSplit);
					if(val == itemSplit || val == childItemSplit){
						$this.find('input[type=hidden]').val('');
					}else{
						$this.find('input[type=hidden]').val(val);
					}
				}
				//1项列表
				else {
					var val = [];
					//循环子项
					$this.children('.list-group').each(function(){
						var $$this = $(this);
						var inputs = $$this.children('input'),
							input0 = inputs.eq(0).val();
						val.push(input0);
					});
					val = val.join(itemSplit);
					if(val == itemSplit || val == childItemSplit){
						$this.find('input[type=hidden]').val('');
					}else{
						$this.find('input[type=hidden]').val(val);
					}
				}
			});
		};
	});
</script>
</body>
</html>